﻿using BLL;
using Microsoft.AspNetCore.Mvc;

namespace TiboShop.Controllers
{
    public class RoleController : Controller
    {
        private readonly BLLType bllType;
        public RoleController(BLLType role)
        {
            bllType = role;
        }
        public IActionResult Index()
        {

            return View(bllType.GetAll());
        }
        public IActionResult RoleManage() 
        {
            return View(bllType.GetAllRole());
        }
        [HttpGet]
        public IActionResult EditRole(int rid)
        {
            return View(bllType.GetRoleById(rid));
        }
        [HttpPost]
        public IActionResult EditRole(int rid, string Name, bool state)
        {
            bllType.ChangeRole(rid, Name, state);
            return RedirectToAction("RoleManage");
        }
        [HttpGet]
        public IActionResult EditType(int tid)
        {
            return View(bllType.GetTypeByID(tid));
        }
        [HttpPost]
        public IActionResult EditType(int tid, string Name, bool state)
        {
            bllType.ChangType(tid, Name, state);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public IActionResult AddType() 
        {
            return View();
        }
        [HttpPost]
        public IActionResult AddType(string name,bool state)
        {
            bllType.AddType(name,state);
            return RedirectToAction("Index");
        }
    }
}
